package org.wtj.controller.sys;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wtj.entity.ResponsePageEntity;
import org.wtj.entity.sys.SysUserConditionEntity;
import org.wtj.entity.sys.SysUserEntity;
import org.wtj.service.sys.SysUserService;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 用户 接口层
 *
 * @author wang 该项目是知识星球：java突击队 的内部项目
 * @date 2025-03-06 21:50:53
 */
@Api(tags = "用户操作", description = "用户接口")
@RestController
@RequestMapping("/v1/sysUser")
public class SysUserController {

	@Autowired
	private SysUserService sysUserService;

	/**
	 * 通过id查询用户信息
	 *
	 * @param id 系统ID
	 * @return 用户信息
	 */
	@ApiOperation(notes = "通过id查询用户信息", value = "通过id查询用户信息")
	@GetMapping("/findById")
	public SysUserEntity findById(Long id) {
		return sysUserService.findById(id);
	}

	/**
    * 根据条件查询用户列表
    *
    * @param sysUserConditionEntity 条件
    * @return 用户列表
    */
	@ApiOperation(notes = "根据条件查询用户列表", value = "根据条件查询用户列表")
	@PostMapping("/searchByPage")
	public ResponsePageEntity<SysUserEntity> searchByPage(@RequestBody SysUserConditionEntity sysUserConditionEntity) {
		return sysUserService.searchByPage(sysUserConditionEntity);
	}


	/**
     * 添加用户
     *
     * @param sysUserEntity 用户实体
     * @return 影响行数
     */
	@ApiOperation(notes = "添加用户", value = "添加用户")
	@PostMapping("/insert")
	public int insert(@RequestBody SysUserEntity sysUserEntity) {
		return sysUserService.insert(sysUserEntity);
	}

	/**
     * 修改用户
     *
     * @param sysUserEntity 用户实体
     * @return 影响行数
     */
	@ApiOperation(notes = "修改用户", value = "修改用户")
	@PostMapping("/update")
	public int update(@RequestBody SysUserEntity sysUserEntity) {
		return sysUserService.update(sysUserEntity);
	}

	/**
     * 批量删除用户
     *
     * @param ids 用户ID集合
     * @return 影响行数
     */
	@ApiOperation(notes = "批量删除用户", value = "批量删除用户")
	@PostMapping("/deleteByIds")
	public int deleteByIds(@RequestBody @NotNull List<Long> ids) {
		return sysUserService.deleteByIds(ids);
	}
}
